package com.oxygen.pt.service.impl;

import cn.hutool.db.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oxygen.pt.mapper.ChamberCheckWeeklyMapper;
import com.oxygen.pt.pojo.entity.ChamberCheckWeekly;
import com.oxygen.pt.pojo.vo.ChamberCheckWeeklyVO;
import com.oxygen.pt.service.ChamberCheckWeeklyService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * 氧舱周巡检报告 Service 实现
 *
 * @author your-name
 * @since 2025-09-02
 */
@Service
public class ChamberCheckWeeklyServiceImpl implements ChamberCheckWeeklyService {

    @Resource
    private ChamberCheckWeeklyMapper chamberCheckWeeklyMapper;

    @Override
    public int save(ChamberCheckWeekly record) {
        return chamberCheckWeeklyMapper.insert(record);
    }

    @Override
    public int remove(Long id) {
        return chamberCheckWeeklyMapper.deleteById(id);
    }

    @Override
    public int update(ChamberCheckWeekly record) {
        return chamberCheckWeeklyMapper.updateById(record);
    }

    @Override
    public ChamberCheckWeekly get(Long id) {
        return chamberCheckWeeklyMapper.selectById(id);
    }

    @Override
    public PageResult<ChamberCheckWeeklyVO> page(String chamberNo,
                                                 LocalDate beginDate,
                                                 LocalDate endDate,
                                                 int current,
                                                 int size) {
        PageHelper.startPage(current, size);                // 1. 设置分页
        List<ChamberCheckWeeklyVO> list =
                chamberCheckWeeklyMapper.selectVoByCondition(chamberNo, beginDate, endDate); // 2. 查询
        PageInfo<ChamberCheckWeeklyVO> pageInfo = new PageInfo<>(list); // 3. 包装
        PageResult<ChamberCheckWeeklyVO> result = new PageResult<>(pageInfo.getPageNum(),
                pageInfo.getPageSize(),
                (int) pageInfo.getTotal());
        result.addAll(pageInfo.getList());
        return result;
    }
}